package com.gxa.saas.controller;

import com.gxa.saas.pojo.Log;
import com.gxa.saas.service.LogService;
import com.gxa.saas.utils.JsonResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: yx
 * @Date: 2022/6/9 10:18
 */
@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    LogService logService;

    @ApiOperation("查询全部")
    @PostMapping("/selectAll")
    public Map selectAll() {
        List<Log> logs = logService.selectAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(logs);
        return jsonResult.getMap();
    }


    @ApiOperation(value = "分页查询日志", produces = "query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "offset", value = "查询页数", paramType = "query")
    })
    @PostMapping("/selectByPage")
    public Map selectByPage(@RequestParam(value = "offset") Integer offset) {
        List<Log> logs = logService.selectByPage(offset);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(logs);
        return jsonResult.getMap();
    }


    @ApiOperation(value = "根据日期删除日志", produces = "delete")
    @ApiImplicitParam(name = "dateline", value = "日期")
    @PostMapping("/delete")
    public Map delete(@RequestParam(value = "dateline",required = false) String dateline) {
        logService.delete(dateline);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        return jsonResult.getMap();
    }

    @ApiOperation("根据名字和日期查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "操作人员"),
            @ApiImplicitParam(name = "dateline", value = "操作日期")
    })
    @PostMapping("/selectByNameAndTime")
    @ResponseBody
    public Map selectByNameAndTime(@RequestParam(value = "username",required = false) String username,@RequestParam(value = "dateline",required = false)String dateline) {
        Map map = new HashMap();
        map.put("username",username);
        map.put("dateline",dateline);
        List<Log> logs = logService.selectByNameAndTime(map);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(logs);
        return jsonResult.getMap();
    }



}
